<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of project
 *
 * @author truongkx
 */
class menu extends SO_Controller{
    //put your code here
    function __construct() {
        parent::__construct('categories');
        $this->load->model('cp/menu_model');
    }
    
    function binding($type='Web'){
        $data = $this->menu_model->binding($type);
        if(isset($data['rows']))
            $data['rows']=$this->menu_model->buildTreeArray($data['rows']);
		if(isset($data['aaData']))
            $data['aaData']=$this->menu_model->buildTreeArray($data['aaData']);
        $R=$data;
        $this->output->set_header('Content-type: application/json');
        $this->output->set_output(json_encode($R));
    }
    
    function gets(){
        $data = $this->menu_model->get_by_type();
        $data=$this->menu_model->buildTreeArray($data);
        $R["result"] = 1;
        $R["message"]='SUCCESS !';
        $R["data"]=$data;
        $this->output->set_header('Content-type: application/json');
        $this->output->set_output(json_encode($R));
    }
    
    function index(){
        echo $c=$this->load->view('cms/cp/02_menu/viewport',$this->assigns,true);
    }
    
    function editpanel($type="Web"){
        $this->assigns->type=$type;
        $data = $this->menu_model->binding($type);
        if(isset($data['aaData'])){
            $data['aaData']=$this->menu_model->buildTreeArray($data['aaData']);
            $this->assigns->cates=$data['aaData'];
        }
        if(isset($data['rows'])){
            $data['rows']=$this->menu_model->buildTreeArray($data['rows']);
            $this->assigns->cates=$data['rows'];
        }
        $Id=(int)$this->input->post('Id');
        if($Id>0)
            $this->assigns->item=$this->menu_model->onGet($Id);
        $c=$this->load->view('cms/cp/02_menu/editpanel',$this->assigns,true);
        $R["result"] = 1;
        $R["message"]='SUCCESS !';
        $R["htmlreponse"]=$c;
        $this->output->set_header('Content-type: application/json');
        $this->output->set_output(json_encode($R));
    }
    
    
}

?>
